const md5 = require('js-md5');
let UserData = {
    user_id: '17',
    user_head: 'http://viquan.droyee.com/Uploads/default.png',
    nick_name: 'V圈15017',
    qrcode: 'http://viquan.droyee.com/Uploads/qrcode/c5/2446761d2a804c922ac796d3ad70f12b.png',
    long_id: '15017',
    login_name: '15078367530',
    phone: '15078367530',
    access_token: 'e10adc3949ba59abbe56e057f20f883e'
};
let VideoList = {
    _list: [],
    recent: 0,
};
let VblogImages = {
    _list: [],
    recent: 0,
};
let QiniuUpload = {
    upToken: { updateTime: '', token: '' },
    getToken: async () => {
        let url = 'http://ling.cash/qiniu/uploadtoken';
        let response = await fetch(url);
        let responseJson = await response.json();
        console.log(response);
        if (responseJson.code == 0) {
            let updateTime = new Date().format("yyyy-MM-dd HH:mm:ss");
            this.token = { token: responseJson.token, updateTime };
            return;
        }
        throw '获取上传token失败,请重新操作';
    },
    put: async (image) => {
        try {
            await this.getToken();
            let formData = new FormData();
            formData.append('token', this.upToken.token);
            let file = { uri: image.path, type: 'multipart/form-data', name: image.filename };
            formData.append('file', file);
            formData.append('key', md5(image.path) + image.filename);
            let opt = {
                body: formData,
                method: 'POST',
            };
            console.log(opt);
            let result = await fetch('http://up-z0.qiniup.com', opt);
            console.log(result);
        }
        catch (err) {
            console.log(err);
        }


    }
}

export {UserData, VideoList, VblogImages, QiniuUpload,};